package com.gaojiawei.multiThread07_ThreeSpecialOrderliness;

import org.junit.Test;

/**
 * Orderliness Demo
 */
public class l01_OrderlinessDemo {

    private static int a,b,x,y;

    @Test
    public void testOrderliness() throws InterruptedException {

        for(int i = 0;i<Integer.MAX_VALUE;i++){
            a = 0;b = 0;x = 0;y = 0;
            Thread thread = new Thread(() -> {
                a = 1;
                x = b;
            });
            Thread thread1 = new Thread(() -> {
                b = 1;
                y = a;
            });

            thread.start();
            thread1.start();

            thread.join();
            thread1.join();

            if(x == 0 && y==0){
                System.out.println("instruction happended in "+i+"times");
            }
        }




    }


}
